package cn.itrip.auth.service;

import cn.itrip.beans.pojo.ItripUser;
import cn.itrip.dao.ItripUserMapper;
import cn.itrip.utlis.RedisAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName : cn.itrip.auth.service.RegService
 * @Description : 类描述
 * Created by Li on 2020-12-22 10:44:36
 */
@Service
public class RegService {
    @Autowired
    private RedisAPI redisAPI;
    @Autowired
    private ItripUserMapper userMapper;

    public String selIdByUserCode(String userCode,String code){
        String type = "";
        if(userCode.indexOf("@")<0){
            type = "手机号码";
        }else {
            type = "邮箱";
        }
        String rCode = redisAPI.get(userCode);
        ItripUser user = userMapper.selectByUserCode(userCode);
        if(user == null){
            return type+ "不存在!";
        }
        if(rCode != null){
            if(!rCode.equals(code))
            return "验证码错误!";
        }
        return user.getId()+"";
    }
}
